package com.yingdong.aop;

import java.lang.reflect.Method;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import com.yingdong.annotation.AutoInvoke;
import com.yingdong.annotation.OpCode;
import com.yingdong.sceneserver.inner.service.GameService;
import com.yingdong.sceneserver.opcode.Dispatcher;

public class SceneServerServicePostProcessor implements BeanPostProcessor {

	static Log logger = LogFactory.getLog(SceneServerServicePostProcessor.class);
	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		for (Method method : bean.getClass().getMethods()) {
			if (method.getAnnotation(OpCode.class) != null) {
				Dispatcher.methodMap.put(method.getAnnotation(OpCode.class).id(), method);
			
			}
			if (method.getAnnotation(AutoInvoke.class) != null) {

			}
		}

		return bean;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		for (Method method : bean.getClass().getMethods()) {

			if (method.getAnnotation(AutoInvoke.class) != null) {

				GameService.listMethod.add(method);

			}
		}
		return bean;
	}

}
